package org.coopac.dao.impl;

import java.util.List;

import org.coopac.dao.ITipoMaestroDAO;
import org.coopac.model.CoopacTipoMaestro;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("TipoMaestroDAO")
public class TipoMaestroDAO extends BaseDaoImpl<CoopacTipoMaestro> implements ITipoMaestroDAO {
	
	@Autowired
	SessionFactory sessionFactory;
	
	@Override
	protected SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
	@Override
	public List<CoopacTipoMaestro> listar() {
		return super.listar(CoopacTipoMaestro.class);
	}

	@Override
	public void save(CoopacTipoMaestro tipoMaestro) {
		super.save(tipoMaestro);
	}

	@Override
	public void update(CoopacTipoMaestro tipoMaestro) {
		super.update(tipoMaestro);
	}
	
	@Override
	public void delete(CoopacTipoMaestro tipoMaestro) {
		super.delete(tipoMaestro);
	}

	@Override
	public CoopacTipoMaestro getById(int id) {
		return (CoopacTipoMaestro) super.getById(CoopacTipoMaestro.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CoopacTipoMaestro> listarByName(String name) {
		@SuppressWarnings("rawtypes")
		List list = getSessionFactory().getCurrentSession().
		createQuery("from CoopacTipoMaestro where familia=(select idTipoMaestro from CoopacTipoMaestro where nombre='"+name+"')").list();
		return list;
	}

}
